package win.larryzeal.mybatis;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import win.larryzeal.mybatis.entity.AuthUser;
import win.larryzeal.mybatis.entity.AuthUserExample;
import win.larryzeal.mybatis.mapper.AuthUserMapper;

import java.io.IOException;
import java.io.Reader;
import java.util.List;

/**
 * Hello world!
 */
public class Main {
    public static void main(String[] args) throws IOException{
        Reader reader = Resources.getResourceAsReader("mybatis-config.xml");
        SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(reader);
        SqlSession sqlSession = factory.openSession();

        AuthUserMapper mapper = sqlSession.getMapper(AuthUserMapper.class);
        AuthUser user=new AuthUser();
        user.setAccountType(0);
        user.setAppId("demo");
        user.setAppKey("demo---key");
        mapper.insert(user);

        AuthUser user2=new AuthUser();
        user2.setAppId(user.getAppId());
        AuthUserExample example=new AuthUserExample();
        AuthUserExample.Criteria criteria = example.createCriteria();
        criteria.andAppIdEqualTo("demo");
        List<AuthUser> authUsers = mapper.selectByExample(example);
        System.out.println(authUsers);
    }
}
